﻿using LJX.SmartPark.Common.Const;
using LJX.SmartPark.Common.ResponseOutput.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Common.ResponseOutput
{
    public class Response<T>
    {
        public string Message { set; get; }

        public ResponseEnum Code { set; get; }

        public T Data { set; get; }

        public int TotalCount { set; get; }

        public static Response<T> Ok(T data, int totalCount = 0, string message = "")
        {
            return new Response<T>()
            {
                Code = ResponseEnum.Success,
                Message = string.IsNullOrEmpty(message) ? ResponseEnum.Success.GetDescription() : message,
                Data = data,
                TotalCount = totalCount
            };
        }

        public static Response<T> Fail(T data)
        {
            return new Response<T>()
            {
                Code = ResponseEnum.Fail,
                Message = ResponseEnum.Fail.GetDescription(),
                Data = data
            };
        }

        public static Response<T> Fail(string message = "")
        {
            return new Response<T>()
            {
                Code = ResponseEnum.Fail,
                Message = string.IsNullOrEmpty(message) ? ResponseEnum.Fail.GetDescription() : message,
            };
        }

        public static Response<T> SystemError(string message = "")
        {
            return new Response<T>()
            {
                Code = ResponseEnum.SystemError,
                Message = string.IsNullOrEmpty(message) ? ResponseEnum.SystemError.GetDescription() : message,
            };
        }

    }
}
